#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else 
  data_date=`date -d "-1 days" +%F`
fi 


#广告表
/opt/module/sqoop/bin/sqoop import  \
--connect jdbc:mysql://node101:3306/ad_date  \
--driver com.mysql.jdbc.Driver  \
--password 123456  \
--username root  \
--delete-target-dir  \
--columns "id,product_id,material_id,group_id,ad_name,materail_url" \
--as-textfile  \
--table ads \
--target-dir "hdfs://node101:8020/warehouse/ad_basic/2024-11-20"/ads \
--compress  \
--compression-codec gzip \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-non-string '\\N'  \
--null-string '\\N'


#推广平台表
/opt/module/sqoop/bin/sqoop import  \
--connect jdbc:mysql://node101:3306/ad_date  \
--driver com.mysql.jdbc.Driver  \
--password 123456  \
--username root  \
--delete-target-dir  \
--columns "id,platform,platform_alias_zh" \
--as-textfile  \
--table platform_info \
--target-dir "hdfs://node101:8020/warehouse/ad_basic/${data_date}"/platform_info \
--compress  \
--compression-codec gzip \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-non-string '\\N'  \
--null-string '\\N'


#商品表
/opt/module/sqoop/bin/sqoop import  \
--connect jdbc:mysql://node101:3306/ad_date  \
--driver com.mysql.jdbc.Driver  \
--password 123456  \
--username root  \
--delete-target-dir  \
--columns "id,name,price" \
--as-textfile  \
--table product \
--target-dir "hdfs://node101:8020/warehouse/ad_basic/${data_date}"/product \
--compress  \
--compression-codec gzip \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-non-string '\\N'  \
--null-string '\\N'

#广告投放表
/opt/module/sqoop/bin/sqoop import  \
--connect jdbc:mysql://node101:3306/ad_date  \
--driver com.mysql.jdbc.Driver  \
--password 123456  \
--username root  \
--delete-target-dir  \
--columns "id,ad_id,platform_id,create_time,cancel_time" \
--as-textfile  \
--table ads_platform \
--target-dir "hdfs://node101:8020/warehouse/ad_basic/${data_date}"/ads_platform \
--compress  \
--compression-codec gzip \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-non-string '\\N'  \
--null-string '\\N'